// 定义积分牌的类
class ScorePanel {
  score: number = 0; // 记录分数
  level: number = 1; // 记录等级
  scoreSpan: HTMLElement;
  levelSpan: HTMLElement;

  // 设置一个变量限制最高等级
  maxLevel: number;
  // 设置一个变量控制多少分升级
  levelScore: number;
  
  constructor(maxLevel: number = 10, levelScore: number = 10) {
    this.maxLevel = maxLevel;
    this.levelScore = levelScore;
    this.scoreSpan = document.getElementById('score')!;
    this.levelSpan = document.getElementById('level')!;
  }

  // 设置加分的方法
  addScore() {
    this.scoreSpan.innerHTML = ++this.score + '';
    // 判断分数
    if (this.score % this.levelScore === 0) {
      this.levelUp();
    }
  }

  // 设置提升等级的方法
  levelUp() {
    if (this.level < this.maxLevel) {
      this.levelSpan.innerHTML = ++this.level + '';
    }
  }
}

// 测试代码
// const scorePanel = new ScorePanel()
// for (let i = 0; i < 100; i++) {
//   scorePanel.addScore();
// }
export default ScorePanel;